<template>
    <div>
        <div class="right" style="margin-bottom:10px">
            <Input style="width:200px" search enter-button placeholder="请输入搜索内容..." v-model="keyWord" @on-search="searchConnectedWorker"/>
        </div>
        <i-table
               border
               stripe
               height="300"
               content="self"
               :columns="columns"
               :data="tableData"
               size="large"
           /><br/>
            <Page  
                :total="pageTotal" 
                :current="pageNum"
                :page-size="pageSize"
                show-elevator
                show-total 
                placement="top" 
                @on-change="handlePage" >
           ></Page>
           <Modal v-model="reset" title="重置密码" @on-ok="resetOk">
                 <div class="center warningInfo">
                    <Icon type="ios-alert" class="warnIcon"/>是否确定重置密码
                   
                </div>
   
           </Modal>
    </div>
</template>
<script>
export default {
    name:'contact_yForm',
    props:['id'],
    data(){
        return{
            row:'',
            reset:false,
            keyWord:'',
            /**给page的属性设置初始值 */
            pageTotal:1,
            pageNum:1,
            pageSize:4,
            columns:[
                {
                    type:'selection',
                    width:50
                },
                {
                    title:'姓名',
                    key:'name'
                },
                {
                    title:'员工编号',
                    key:'number'
                },
                {
                    title:'职称',
                    key:'positionTitle'
                },
                {
                    title:'职位',
                    key:'position'
                },
                {   
                    title:'账号',
                    key:'username'
                },
                {
                    title:'操作',
                    key:'action',
                    render: (h, params) => {
                            return h('Button',{
                                props:{
                                    type:'primary'
                                },
                                on:{
                                     click:()=>{this.resetAction(params.row)}
                                }
                            },'重置密码');
                    }
                }
             ],
            tableData:[],
            
            }
        },
    beforeMount(){
        this.getConnectedWorkers();
    },

    methods:{
            resetAction(row){
               // console.log("选中行信息：",row);
                this.row=row;
                this.reset=true
            },
            //翻页
            handlePage(value){
                this.pageNum=value;
                this.getConnectedWorkers();
            },
            /**得到该角色下关联的员工信息 */
            getConnectedWorkers(){
                this.apis.roleApis.linkedPersons(this.keyWord,this.id,this.pageNum,this.pageSize,res=>{
                    var code=res.code;
                    if(code===0){
                        this.pageTotal=res.data.total;
                       this.tableData=res.data.list;
                    }else{
                        this.$Message.error(res.msg);
                    }
                })
            },
            /**搜索关联员工 */
            searchConnectedWorker(){
                this.getConnectedWorkers();
            },
            /**确认重置密码的回调 */
            resetOk(){
                this.apis.roleApis.passwordReset([this.row.loginId],res=>{
                    var code=res.code;
                    if(code===0){
                       this.$Message.success(res.data);
                    }else{
                        this.$Message.error(res.msg);
                    }
                })
            },
        }
}
</script>
<style scoped>

@import "../../../../../static/global.css"; /*引入公共样式*/
</style>
